package behaviors

import (
	"context"
	"log"

	"github.com/mehdihadeli/go-mediatr"
)

type RequestLoggerBehavior struct {
}

func (r *RequestLoggerBehavior) Handle(ctx context.Context, request any, next mediatr.RequestHandlerFunc) (any, error) {
	log.Printf("logging before handling the request")

	ctx = context.WithValue(ctx, "logger_pipeline", true)

	response, err := next(ctx)
	if err != nil {
		return nil, err
	}
	log.Println("logging after handling the request")
	return response, nil
}
